<?php
$dbms='mysql';     //数据库类型
$host='localhost'; //数据库主机名
$dbName='samagrph_sama';    //使用的数据库
$user='samagrph_sama';      //数据库连接用户名
$pass='Sama@123';          //对应的密码
$dsn="$dbms:host=$host;dbname=$dbName";
$tmp = array();
$nick_name = $_POST['nick_name'];
$phone = $_POST['phone'];
$info = $_POST['info'];
$img_url_back = $_POST['img_url_back'];
$img_url_front = $_POST['img_url_front'];
$img_url_placards = $_POST['img_url_placards'];
try {
    $dbh = new PDO($dsn, $user, $pass); //初始化一个PDO对象
    $dbh->exec("SET NAMES 'utf8';"); 

//    echo "连接成功<br/>";
    $count = $dbh->exec("INSERT INTO user (nick_name, phone,info,img_url_back,img_url_front,img_url_placards)
VALUES ('$nick_name','$phone','$info','$img_url_back','$img_url_front','$img_url_placards')");
    $dbh = null;
    if ($count >= 1) {
    $tmp['data'] = 'success';
    echo json_encode($tmp);exit;
    }
} catch (PDOException $e) {
    die ("Error!: " . $e->getMessage() . "<br/>");
}
//默认这个不是长连接，如果需要数据库长连接，需要最后加一个参数：array(PDO::ATTR_PERSISTENT => true) 变成这样：
//$db = new PDO($dsn, $user, $pass, array(PDO::ATTR_PERSISTENT => true));
